let MYGAMEOBJECTS=[];

export class MyGameObject{
    constructor(){
        MYGAMEOBJECTS.push(this);
        this.timedelta=0;
        this.has_called_start=false;
    }

    start(){

    }

    update(){

    }

    destroy(){
        for(let i in MYGAMEOBJECTS){
            if(MYGAMEOBJECTS[i]===this){
                MYGAMEOBJECTS.splice(i,1);
                break;
            }
        }
    }
}

let last_timestamp;

let MYGAMEOBJECTSFRAME=function(timestamp){
    for(let obj of MYGAMEOBJECTS){
        if(!obj.has_called_start){
            obj.start();
            obj.has_called_start=true;
        }else{
            obj.timedelta=timestamp-last_timestamp;
            obj.update();
        }
    }
    last_timestamp=timestamp;
    requestAnimationFrame(MYGAMEOBJECTSFRAME);
}

requestAnimationFrame(MYGAMEOBJECTSFRAME);